<template>
  <div>
    <el-dialog title="审核权限" :visible.sync="dialogShow">
      <el-form>
        <el-form-item label="审核权限" :label-width="formLabelWidth">
          <el-switch
            v-model="examine_status"
            active-color="#13ce66"
            inactive-color="#aaaaaa"
          />
        </el-form-item>
        <el-form-item v-if="examine_status" label="审核等级" :label-width="formLabelWidth">
          <el-checkbox-group v-model="checkList">
            <el-checkbox v-for="item in levels" :key="item.id" :label="item.level_name" />
          </el-checkbox-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogShow = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { setExamineStatusApi } from '@/api/agent'
export default {
  data() {
    return {
      dialogShow: false,
      examine_status: false,
      formLabelWidth: '100px',
      levels: [],
      checkList: [],
      brand_id: '',
      anent_id: ''
    }
  },
  methods: {
    submit() {
      console.log(this.examine_status)
      console.log(this.checkList)
      const examine_content = this.checkListVal(this.checkList)
      console.log(examine_content)
      const data = {
        anent_id: this.anent_id,
        brand_id: this.brand_id,
        examine_status: this.examine_status ? '1' : '0',
        examine_content: JSON.stringify(examine_content)
      }
      console.log(data)
      setExamineStatusApi(data).then(res => {
        if (res.code === 200) {
          this.$message.success('权限设置成功！')
          this.dialogShow = false
          this.$emit('reloadFun')
        }
      })
    },
    checkListVal(list) {
      const examineContent = []
      list.forEach(item => {
        this.levels.forEach(level => {
          if (level.level_name === item) {
            examineContent.push(level.level_int)
          }
        })
      })
      return examineContent
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
